package controllers

import (
	"api_admin_server/internal/services"
	"bytes"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"jihe.common/oss"
	"jihe.common/protos/auth_server"
	"jihe.common/protos/calculate_server"
	"strconv"
	"strings"
	"time"

	"github.com/gin-gonic/gin"
	common "jihe.common"
	auth_server_proto "jihe.common/protos/auth_server/proto"
	"jihe.common/protos/base_server"
	"jihe.common/protos/base_server/proto"
	calculate_server_proto "jihe.common/protos/calculate_server/proto"
	"jihe.common/resp"
	"jihe.common/tool"
)

type BaseControoler struct {
	Redis               common.Redis
	FashionCheckService services.FashionCheck
}

func (s *BaseControoler) BatchCreateFashion(c *gin.Context) {
	req := proto.BaseFashion{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.DxfUrl == "" || req.ObjUrl == "" {
		resp.RespParamErr(c)
		return
	}
	err = s.Redis.Publish(s.Redis.GetBaseBatchCreateFashionConsumeKey(), req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	s.Redis.Get().Incr(s.Redis.GetBaseBatchCreateFashionLastNumKey())
	resp.RespOk(c)
}

func (s *BaseControoler) GetBatchCreateFashionLastNum(c *gin.Context) {
	redisClient := s.Redis.Get()
	ret := redisClient.Get(s.Redis.GetBaseBatchCreateFashionLastNumKey()).Val()
	resp.RespOk(c, ret)
}

func (s *BaseControoler) ClearAlgorithmConfig(c *gin.Context) {
	err := s.Redis.Get().Del(s.Redis.GetBaseAlgorithmConfigKey()).Err()
	if err != nil {
		common.Loger.Error("ClearAlgorithmConfig err:%v", err)
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) UpdateAlgorithmConfig(c *gin.Context) {
	req := &proto.BaseAlgorithmConfig{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseUpdateAlgorithmConfig(c, req)
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) CreateFashion(c *gin.Context) {
	req := &proto.BaseFashion{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Name == "" || req.PersonType <= 0 || req.SolarTerm == "" || req.Tp <= 0 || req.Style <= 0 || req.Price <= 0 || req.Cover == "" || req.DetailUrl == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseCreateFashion(c, req)
	if err != nil {
		if strings.Contains(err.Error(), "fashions_name_udx") {
			resp.RespGeneralErr(c, "已有相同款式名")
			return
		}
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) GetFashionList(c *gin.Context) {
	req := &proto.BaseGetFashionListReq{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Page <= 0 {
		req.Page = 1
	}
	if req.PageSize <= 0 || req.PageSize > 100 {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseGetFashionList(c, req)
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) GetFashionDetail(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseGetFashionDetail(c, &proto.BaseGetFashionDetailReq{
		Id: id,
	})
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) UpdateFashion(c *gin.Context) {
	req := proto.BaseFashion{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Id == "" || req.Name == "" || req.PersonType <= 0 || req.SolarTerm == "" || req.Tp <= 0 || req.Style <= 0 || req.Price <= 0 || req.Cover == "" || req.DetailUrl == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseUpdateFashion(c, &req)
	if err != nil {
		if strings.Contains(err.Error(), "fashions_name_udx") {
			resp.RespGeneralErr(c, "已有相同款式名")
			return
		}
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) UpdateFashionObj(c *gin.Context) {
	if c.Request.Method == "GET" {
		flag := c.Query("flag")
		if flag == "" {
			resp.RespParamErr(c)
			return
		}
		redisClient := s.Redis.Get()
		taskFlag := redisClient.Get(flag).Val()
		resp.RespOk(c, taskFlag)
		return
	}
	objUrl := c.Query("obj_url")
	if objUrl == "" {
		resp.RespParamErr(c)
		return
	}
	fashionId := c.Query("fashion_id")
	if fashionId == "" {
		resp.RespParamErr(c)
		return
	}
	_, err := base_server.HandleUpdateObjUrl(c, &proto.HandleUpdateObjUrlReq{FashionId: fashionId, ObjUrl: objUrl})
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	resp.RespOk(c, s.Redis.GetUploadFashionObjKey(fashionId))
}

func (s *BaseControoler) SplitObj(c *gin.Context) {
	objUrl := c.Query("obj_url")
	if objUrl == "" {
		resp.RespParamErr(c)
		return
	}
	fashionId := c.Query("fashion_id")
	if fashionId == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := tool.SplitObj(objUrl)
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	if len(ret) == 0 {
		resp.RespGeneralErr(c)
		return
	}
	_, err = base_server.BaseUpdateFashionItemObj(c, &proto.BaseCutparts{
		BaseCutpartList: ret,
		ObjUrl:          objUrl,
		FashionId:       fashionId,
	})
	if err != nil {
		common.Loger.Error("SplitObj BaseUpdateFashionItemObj err:%v", err)
		resp.RespInternalErr(c)
		return
	}
	//将分割后的obj分离出v和vt边缘点

	resp.RespOk(c, ret)
}

func (s *BaseControoler) DeleteFashion(c *gin.Context) {
	fashionId := c.Query("fashion_id")
	if fashionId == "" {
		resp.RespParamErr(c)
		return
	}
	_, err := base_server.BaseFashionDelete(c, &proto.BaseFashion{Id: fashionId})
	if err != nil {
		if strings.Contains(err.Error(), "errorno=1") {
			resp.RespGeneralErr(c, "款式已被使用，不能删除")
			return
		}
	}
	resp.RespOk(c)
}

func (s *BaseControoler) OffonFashion(c *gin.Context) {
	action := c.Query("action")
	fashionId := c.Query("fashion_id")
	if fashionId == "" {
		resp.RespParamErr(c)
		return
	}
	if action == "check" {
		fashionDetail, err := base_server.BaseGetFashionDetail(c, &proto.BaseGetFashionDetailReq{Id: fashionId})
		if err != nil {
			resp.RespInternalErr(c, err.Error())
			return
		}
		if len(fashionDetail.Fashion.AlgorithmParam.Wedo) == 0 {
			resp.RespGeneralErr(c, "请设置廓形")
			return
		}
		if fashionDetail.Fashion.AlgorithmParam.Wedo["kuoxing"] == "" {
			resp.RespGeneralErr(c, "请设置廓形")
			return
		}
		if fashionDetail.Fashion.ObjUrl == "" {
			resp.RespGeneralErr(c, "请上传obj")
			return
		}
		if fashionDetail.Fashion.DxfUrl == "" {
			resp.RespGeneralErr(c, "请上传dxf")
			return
		}
		isHasFabric := false
		for _, v := range fashionDetail.BaseCutpartList {
			if v.FabricIds != "" {
				isHasFabric = true
				break
			}
		}
		if !isHasFabric {
			resp.RespGeneralErr(c, "请为裁片选择面料")
			return
		}
		resp.RespOk(c)
		return
	}
	if action == "on" {
		fashionDetail, err := base_server.BaseGetFashionDetail(c, &proto.BaseGetFashionDetailReq{Id: fashionId})
		if err != nil {
			resp.RespInternalErr(c, err.Error())
			return
		}
		if len(fashionDetail.Fashion.AlgorithmParam.Wedo) == 0 {
			resp.RespGeneralErr(c, "请设置廓形")
			return
		}
		if fashionDetail.Fashion.AlgorithmParam.Wedo["kuoxing"] == "" {
			resp.RespGeneralErr(c, "请设置廓形")
			return
		}
		if fashionDetail.Fashion.ObjUrl == "" {
			resp.RespGeneralErr(c, "请上传obj")
			return
		}
		if fashionDetail.Fashion.DxfUrl == "" {
			resp.RespGeneralErr(c, "请上传dxf")
			return
		}
		isHasFabric := false
		for _, v := range fashionDetail.BaseCutpartList {
			if v.FabricIds != "" {
				isHasFabric = true
				break
			}
		}
		if !isHasFabric {
			resp.RespGeneralErr(c, "请为裁片选择面料")
			return
		}
		_, err = base_server.BaseFashionOffline(c, &proto.BaseFashion{
			Id:     fashionId,
			Status: 2,
		})
		if err != nil {
			resp.RespInternalErr(c, err.Error())
			return
		}
		resp.RespOk(c)
		return
	}
	if action == "off" {
		_, err := base_server.BaseFashionOffline(c, &proto.BaseFashion{
			Id:     fashionId,
			Status: 1,
		})
		if err != nil {
			resp.RespInternalErr(c, err.Error())
			return
		}
		resp.RespOk(c)
		return
	}
	resp.RespParamErr(c)
}

func (s *BaseControoler) SetFashionRecommended(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	recommended := c.Query("recommended")
	recommendedInt64, err := strconv.ParseInt(recommended, 10, 64)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseSetRecommendedFashion(c, &proto.BaseFashion{Id: id, Recommended: recommendedInt64})
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) UpdateFashionDxf(c *gin.Context) {
	fashionId := c.Query("fashion_id")
	dxfUrl := c.Query("dxf_url")
	if fashionId == "" || dxfUrl == "" {
		resp.RespParamErr(c)
		return
	}
	_, err := base_server.BaseUpdateFashionDxf(c, &proto.BaseFashion{
		Id:     fashionId,
		DxfUrl: dxfUrl,
	})
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) UpdateFashionAlgorithmParam(c *gin.Context) {
	req := proto.BaseFashion{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseUpdateFashionAlgorithmParam(c, &req)
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) DeleteCutpart(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	_, err := base_server.BaseDeleteCutpart(c, &proto.BaseCutpart{
		Id: id,
	})
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) GetCutpartDetail(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseGetCutpartDetail(c, &proto.BaseCutpart{
		Id: id,
	})
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	out, resultErr, isKilled := tool.RunCommandWithTimeout(3000, "python3", fmt.Sprintf("%s/getCutpartPoint.py", common.Configer.ScriptPath), ret.ObjUrl)
	if isKilled {
		common.Loger.Error("script getCutpartPoint timeout err:%s", resultErr)
		resp.RespInternalErr(c)
		return
	}
	points := make([][]float64, 0)
	err = json.Unmarshal([]byte(out), &points)
	if err != nil {
		common.Loger.Error("script getCutpartPoint err:%v data:%s resultErr:%s", err, out, resultErr)
		resp.RespInternalErr(c)
		return
	}
	retMap := make(map[string]interface{})
	retMap["points"] = points
	retMap["detail"] = ret
	resp.RespOk(c, retMap)
}

func (s *BaseControoler) UpdateCutpart(c *gin.Context) {
	req := proto.BaseCutpart{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Id == "" {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseUpdateCutpart(c, &req)
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) UpdateCutpartFabric(c *gin.Context) {
	req := proto.BaseUpdateCutpartFabricReq{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if len(req.CutpartIds) == 0 {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseUpdateCutpartFabric(c, &req)
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) CreateFabric(c *gin.Context) {
	req := proto.BaseFabric{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Name == "" || req.Weave <= 0 || req.Width <= 0 || req.Needle <= 0 || req.Discount <= 0 || req.Material <= 0 || req.Count <= 0 || req.G <= 0 || req.WarmNum <= 0 || req.Line <= 0 || req.Url == "" {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseCreateFabric(c, &req)
	if err != nil {
		if strings.Contains(err.Error(), "fabrics_name_udx") {
			resp.RespGeneralErr(c, "已有相同布料名")
			return
		}
		common.Loger.Error("CreateFabric err:%v", err)
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) UpdateFabric(c *gin.Context) {
	req := proto.BaseFabric{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Id == "" || req.Name == "" || req.Weave <= 0 || req.Width <= 0 || req.Needle <= 0 || req.Discount <= 0 || req.Material <= 0 || req.Count <= 0 || req.G <= 0 || req.WarmNum <= 0 || req.Line <= 0 || req.Url == "" {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseUpdateFabric(c, &req)
	if err != nil {
		if strings.Contains(err.Error(), "fabrics_name_udx") {
			resp.RespGeneralErr(c, "已有相同布料名")
			return
		}
		common.Loger.Error("UpdateFabric err:%v", err)
		resp.RespGeneralErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) GetFabricDetail(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseGetDetailFabric(c, &proto.BaseFabric{
		Id: id,
	})
	if err != nil {
		resp.RespGeneralErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) DeleteFabric(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseDeleteFabric(c, &proto.BaseFabric{
		Id: id,
	})
	if err != nil {
		if strings.Contains(err.Error(), "errorno=1") {
			resp.RespGeneralErr(c, "该布料已被裁片使用")
			return
		}
		resp.RespGeneralErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) GetFabricList(c *gin.Context) {
	ret, err := base_server.BaseGetListFabric(c, &proto.BaseGetListFabricReq{})
	if err != nil {
		resp.RespGeneralErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) CreatePattern(c *gin.Context) {
	req := proto.BasePattern{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Name == "" || req.Style <= 0 || req.Tp <= 0 || req.Price < 0 || req.Url == "" {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseCreatePattern(c, &req)
	if err != nil {
		if strings.Contains(err.Error(), "patterns_name_udx") {
			resp.RespGeneralErr(c, "已有相同纹样名")
			return
		}
		common.Loger.Error("CreatePattern err:%v", err)
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) UpdatePattern(c *gin.Context) {
	req := proto.BasePattern{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Id == "" || req.Name == "" || req.Style <= 0 || req.Tp <= 0 || req.Price < 0 || req.Url == "" {
		resp.RespParamErr(c)
		return
	}
	_, err = base_server.BaseUpdatePattern(c, &req)
	if err != nil {
		if strings.Contains(err.Error(), "patterns_name_udx") {
			resp.RespGeneralErr(c, "已有相同纹样名")
			return
		}
		common.Loger.Error("UpdatePattern err:%v", err)
		resp.RespGeneralErr(c)
		return
	}
	resp.RespOk(c)
}

func (s *BaseControoler) GetPatternDetail(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseGetPatternDetail(c, &proto.BasePattern{
		Id: id,
	})
	if err != nil {
		resp.RespGeneralErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) DeletePattern(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseDeletePattern(c, &proto.BasePattern{
		Id: id,
	})
	if err != nil {
		resp.RespGeneralErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) GetPatternList(c *gin.Context) {
	req := proto.BaseGetPatternListReq{}
	err := c.BindJSON(&req)
	if err != nil {
		resp.RespParamErr(c)
		return
	}
	if req.Page <= 0 {
		req.Page = 1
	}
	if req.PageSize <= 0 {
		req.PageSize = 20
	}
	if req.PageSize > 100 {
		resp.RespParamErr(c)
		return
	}
	ret, err := base_server.BaseGetPatternList(c, &req)
	if err != nil {
		common.Loger.Error("GetPatternList err:%v", err)
		resp.RespInternalErr(c)
		return
	}
	resp.RespOk(c, ret)
}

func (s *BaseControoler) RobotLogin(c *gin.Context) {
	//机器人ID固定是1
	tokenRes, err := auth_server.CreateToken(c, &auth_server_proto.CreateTokenReq{
		Uid: "1",
	})
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	resp.RespOk(c, tokenRes)
}

func (s *BaseControoler) CopySuperFashionCraft(c *gin.Context) {
	id := c.Query("id")
	if id == "" {
		resp.RespParamErr(c)
		return
	}
	detail, err := base_server.BaseGetFashionDetail(c, &proto.BaseGetFashionDetailReq{Id: id})
	if err != nil {
		resp.RespInternalErr(c)
		return
	}
	if detail.Fashion.SuperFashionId == "" {
		resp.RespGeneralErr(c, "暂无母板信息")
		return
	}
	bucket, err := oss.GetClient().Bucket("jihe-file")
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	superCraftUrl := fmt.Sprintf("%s/%s_crafts/%s.json?%d", common.Configer.Oss.Domain, common.Configer.Runmode, detail.Fashion.SuperFashionId, tool.GetSnowflakeId())
	response, body, errs := tool.GetRequest().Get(superCraftUrl).Timeout(time.Second * 10).EndBytes()
	if response.StatusCode == 200 && len(errs) == 0 {
		currentCraftUrl := fmt.Sprintf("%s_crafts/%s.json", common.Configer.Runmode, id)
		err = bucket.PutObject(currentCraftUrl, bytes.NewReader(body))
		if err != nil {
			resp.RespInternalErr(c, err.Error())
			return
		}
	}
	resp.RespOk(c)
}

func (s *BaseControoler) GetDxfInfo(c *gin.Context) {
	fashionId := c.Query("fashion_id")
	if fashionId == "" {
		resp.RespParamErr(c)
		return
	}
	fashionDetail, err := base_server.BaseGetFashionDetail(c, &proto.BaseGetFashionDetailReq{Id: fashionId})
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	if fashionDetail.Fashion.DxfUrl == "" {
		resp.RespGeneralErr(c, "请上传dxf文件")
		return
	}
	if len(fashionDetail.BaseCutpartList) == 0 {
		resp.RespGeneralErr(c, "请上传obj文件")
		return
	}
	if fashionDetail.Fashion.AlgorithmParam == nil {
		resp.RespGeneralErr(c, "请填写uv值")
		return
	}
	vtInfos := make([]base_server.VtInfo, 0)
	_, orgjsonByte, errs := tool.GetRequest().Get(strings.Replace(fashionDetail.Fashion.CutpartBorderPoint, "files.dizanz", "jihe-file.oss-cn-beijing-internal.aliyuncs", -1)).EndBytes()
	if len(errs) != 0 {
		resp.RespGeneralErr(c, errs[0].Error())
		return
	}
	err = json.Unmarshal(orgjsonByte, &vtInfos)
	if err != nil {
		resp.RespGeneralErr(c, err.Error())
		return
	}
	for _, v := range fashionDetail.BaseCutpartList {
		getDxfInfoReq := base_server.DxfInfoReq{}
		getDxfInfoReq.CpName = v.Code
		getDxfInfoReq.DxfPath = strings.Replace(fashionDetail.Fashion.DxfUrl, "files.dizanz", "jihe-file.oss-cn-beijing-internal.aliyuncs", -1)
		getDxfInfoReq.ResourcePath = strings.Replace(v.ObjUrl, "files.dizanz", "jihe-file.oss-cn-beijing-internal.aliyuncs", -1)
		//getDxfInfoReq.UvcloLength = fashionDetail.Fashion.AlgorithmParam.UvWidth
		getDxfInfoReqByte, _ := json.Marshal(getDxfInfoReq)
		dxfInfoRet, err := calculate_server.GetDxfInfo(c, &calculate_server_proto.GetDxfInfoReq{
			Base64: base64.StdEncoding.EncodeToString(getDxfInfoReqByte),
		})
		if err != nil {
			resp.RespInternalErr(c, err.Error())
			return
		}
		dxfInfo := base_server.DxfInfo{}
		err = json.Unmarshal([]byte(dxfInfoRet.Stdout), &dxfInfo)
		if err != nil {
			resp.RespInternalErr(c, err.Error()+base64.StdEncoding.EncodeToString(getDxfInfoReqByte)+dxfInfoRet.Stdout)
			return
		}
		for dx, item := range vtInfos {
			if item.Code == v.Code {
				vtInfos[dx].DxfInfo = dxfInfo
			}
		}
	}
	bucket, err := oss.GetClient().Bucket("jihe-file")
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	jsonByte, err := json.Marshal(vtInfos)
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	fileName := fmt.Sprintf("%s/%d.json", time.Now().Format("2006-01-02"), tool.GetSnowflakeId())
	err = bucket.PutObject(fileName, bytes.NewReader(jsonByte))
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	_, err = base_server.UpdateBorderPointUrlById(c, &proto.UpdateBorderPointUrlByIdReq{Id: fashionId, Url: "https://files.dizanz.com/" + fileName})
	if err != nil {
		resp.RespInternalErr(c, err.Error())
		return
	}
	resp.RespOk(c)
}
